package com.spc.car.common.utils.text.gson;

import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

public class IgnoreFieldStrategy implements ExclusionStrategy {
    private List<String> fldNameList = new ArrayList();
    private boolean inclusive = true;

    public IgnoreFieldStrategy(List<String> fldNameList, boolean inclusive) {
        this.fldNameList = fldNameList;
        this.inclusive = inclusive;
    }

    public boolean shouldSkipClass(Class<?> clazz) {
        return false;
    }

    public boolean shouldSkipField(FieldAttributes fieldAttributes) {
        Collection<Annotation> annotations = fieldAttributes.getAnnotations();
        Iterator var3 = annotations.iterator();

        while(var3.hasNext()) {
            Annotation annotation = (Annotation)var3.next();
            if (annotation.annotationType() == GsonIgnore.class) {
                return true;
            }
        }

        if (null != this.fldNameList && !this.fldNameList.isEmpty()) {
            String fldName = fieldAttributes.getName();
            return (!this.inclusive || !this.fldNameList.contains(fldName)) && (this.inclusive || this.fldNameList.contains(fldName));
        } else {
            return false;
        }
    }
}

